// contentStore.ts
import { defineStore } from 'pinia';
import { addComment, getComments,getCommentCount,deleteComment } from '@/api/study/bizCourseVideoCommentController';

export const useVideoCommentStore = defineStore('VideoComment', {
  actions: {
    /**
     * 获取视频评论
     * @param videoId 视频ID
     * @returns 评论列表
     */
    async fetchComments(videoId: string) {
      try {
        const response = await getComments({ videoId });
        return response.data || [];
      } catch (error) {
        console.error('获取评论失败:', error);
        throw error;
      }
    },
    /**
     * 获取视频评论数量
     * @param videoId 视频ID
     * @returns 评论数量
     */
    async fetchCommentCount(videoId: string) { // 新增方法
      try {
        const response = await getCommentCount({ videoId });
        return response.data || 0;
      } catch (error) {
        console.error('获取评论数量失败:', error);
        return 0;
      }
    },

    /**
     * 发送评论
     * @param params 评论参数
     */
    async sendComment(params: {
      userId: string;
      userName: string;
      videoId: string;
      content: string;
      filePath:string;
    }) {
      try {
        await addComment(params);
      } catch (error) {
        console.error('发送评论失败:', error);
        throw error;
      }
    },
    /**
     * 删除评论（修正语法错误）
     * @param params 删除参数
     * @returns 是否删除成功
     */
    async deleteComment(params: {  // 此处修正了语法错误
      commentId: string;
      videoId: string;
      userId: string;
    }) {
      try {
        const response = await deleteComment(params);
        return response.data || false;
      } catch (error) {
        console.error('删除评论失败:', error);
        throw error;
      }
    }
  }
});